<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<style>
    #topbutt{margin: 0 10px 10px;padding: 8px 15px;position: relative}
    #topbutt button{margin-right: 10px;height: 30px;line-height: 30px}
    #topbutt .active{background-color:#2272eb;color: #FFFFFF}
    #tree_content button{width: 80%;margin-left: 10%!important;margin-top: 5px;height: 26px;line-height: 20px;}
    #tree_content .active{background-color:#2272eb;color: #FFFFFF}
</style>
<body class="laytp-container" style="overflow-y: hidden">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">从基准费用选择</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>


<div class="layui-card" id="topbutt">
    <div>
        <button class="layui-btn layui-btn-primary active" key="1" type="button">人工费</button>
        <button class="layui-btn layui-btn-primary" key="2" type="button">材料费</button>
        <button class="layui-btn layui-btn-primary" key="3" type="button">机械费</button>
        <button class="layui-btn layui-btn-primary" key="4" type="button">分包费</button>
    </div>
    <div style="color: red;position: absolute;top:15px;right: 15px">可双击直接载价</div>
</div>


<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md2" id="engindao">
                <div class="engindao_bac">
                    <div class="engindao_div">
                        <div class="engindao_title">类别导航</div>
                        <div class="engindao_nav">
                            <a id="engindao_left"><i class="layui-icon layui-icon-left"></i></a>
                        </div>
                    </div>
                    <div id="tree_content">
<!--                        <button class="layui-btn layui-btn-primary active" type="button">分包费</button>-->
                    </div>
                </div>
            </div>
            <div class="layui-col-md2 layui-hide" id="engindaomin">
                <div class="engindao_bg">
                    <div class="col" id="engindao_right"><a><i class="layui-icon layui-icon-right"></i></a></div>
                    <div class="engindao_title">类别导航</div>
                </div>
            </div>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card" id="search-form">
                    <div class="layui-card-body">
                        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
                            <div class="layui-form-item">
                                <div class="layui-row">
                                    <div class="layui-col-md3">
                                        <div class="layui-input-block" style="margin-left: 0!important;">
                                            <input type="text" name="keyword" placeholder="名称 \ 特征描述 \ 单位\ 备注" class="layui-input" autocomplete="off">
                                        </div>
                                    </div>
                                    <div class="layui-col-md3">
                                        <div class="layui-form-item search-div">
                                            <div class="layui-form-item layui-inline">
                                                <input type="hidden" id="basetype" name="basetype" value="">
                                                <input type="hidden" id="type" name="type" value="0">
                                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>



<script type="text/javascript">
    $("#engindao #engindao_left").click(function () {
        var cliHeight = document.getElementById('engindao').clientHeight;

        $("#engindao").addClass('layui-hide');
        $("#table-card #table_list").addClass('engindaomin_guan');

        document.getElementById('engindaomin').style.height = cliHeight+"px";
        $("#engindaomin").removeClass('layui-hide');
    });
    $("#engindaomin #engindao_right").click(function () {
        $("#engindao").removeClass('layui-hide');
        $("#table-card #table_list").removeClass('engindaomin_guan');
        $("#engindaomin").addClass('layui-hide');
    });






    var parent_enginid = getQueryVariable('enginid') || 0;
    var parent_page = getQueryVariable('page');
    var parent_type = getQueryVariable('type');
    var parent_basetype = decodeURI(getQueryVariable('fenname')) || '';
    $("#type").val(parent_type);
    $("#basetype").val(parent_basetype);

    $("#topbutt button").removeClass('active');
    $("#topbutt button[key='"+parent_type+"']").addClass('active');


    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#topbutt button").click(function () {
            $("#topbutt button").removeClass('active');
            $(this).addClass('active');
            var xuantype = $(this).attr('key') || 1;
            $("#type").val(xuantype);
            $("#basetype").val('');
            searchTableFunc(form, table)
        });

        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_main_check_mark),where: {enginid:parent_enginid,type:parent_type,basetype:parent_basetype}, page: false, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){

                //
                var basetypearr = res.data.basetypearr
                var str = '';
                var isquanbu = true;
                for (var key in basetypearr){
                    if(res.data.basetype == basetypearr[key]){
                        isquanbu = false;
                        str += '<button class="layui-btn layui-btn-primary active" type="button">'+basetypearr[key]+'</button>';
                    }else{
                        str += '<button class="layui-btn layui-btn-primary" type="button">'+basetypearr[key]+'</button>';
                    }
                }
                var quanStr = '';
                if(isquanbu){
                    quanStr += '<button class="layui-btn layui-btn-primary active" type="button">全部</button>';
                }else{
                    quanStr += '<button class="layui-btn layui-btn-primary" type="button">全部</button>';
                }

                $("#tree_content").html(quanStr+str);
                $("#tree_content button").click(function () {
                    var xuanname = $(this).text() || '';
                    if(xuanname == '全部'){
                        xuanname = '';
                    }
                    $("#basetype").val(xuanname);
                    searchTableFunc(form, table)
                });



                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.data
                };
            }
            ,cols: [[
                {type:'checkbox',fixed:'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field:'name',title:'名称'}
                ,{field:'basetype',title:'类别'}
                ,{field:'guige',title:'特征描述',minWidth:250}
                ,{field: 'valunit', title: '单位',width:60}
                ,{field: 'content', title: '含量'}
                ,{field: 'loss_rate', title: '损耗率'}
                ,{field: 'no_price', title: '不含税单价'}
                ,{field: 'price', title: '成本单价'}
                ,{field: 'explain', title: '备注'}
            ]]
            ,done : function(res, curr, count){
                soulTable.render(this);
                var tabboxhei = $(".layui-table-body").height()
                $("#tree_content").attr('style','height:'+(tabboxhei+68)+'px;overflow-y: auto')
                $(".layui-table-tool").remove();
            }
        });
        listTableSearch(form, table);

        tbaleFilterRowDouble(table, 'datalist', function (obj, objdata) {
            if(parent_page == 'basal'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;

                var typeArr = parent.typeArr;
                var basetypeArr = parent.basetypeArr;

                var str = '';
                var data = [objdata]
                for (var key in data){
                    if(parent_type == 3 || parent_type == 4){
                        data[key].content_exp = 1;
                        data[key].content = 1;
                        data[key].loss_rate = 0;
                    }




                    nums++;
                    str += '<tr>';
                    str += '<td class="td1" style="width: 45px">'+nums+'</td>';
                    str += '<td class="td2"><select class="layui-select type" lay-filter="type">';
                    str += '<option value="">请选择</option>';
                    for(var j in typeArr){
                        if(data[key].type == j){
                            str += '<option value="'+j+'" selected>'+typeArr[j]+'</option>';
                        }else{
                            str += '<option value="'+j+'">'+typeArr[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td class="td3"><select class="layui-select basetype">';
                    str += '<option value="">请选择</option>';

                    var this_basetype = basetypeArr[data[key].type];
                    for(var j=0;j<this_basetype.length;j++){
                        if(data[key].basetype == this_basetype[j].name){
                            str += '<option value="'+this_basetype[j].name+'" selected>'+this_basetype[j].name+'</option>';
                        }else{
                            str += '<option value="'+this_basetype[j].name+'">'+this_basetype[j].name+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td class="td4"><input type="text" class="layui-input name" value="'+data[key].name+'"></td>';
                    str += '<td class="td5"><textarea class="layui-textarea curarea guige">'+data[key].guige+'</textarea></td>';
                    str += '<td class="td6"><input type="text" class="layui-input valunit" value="'+data[key].valunit+'"></td>';
                    str += '<td class="td7"><input type="text" class="layui-input content_exp" value="'+data[key].content_exp+'"></td>';
                    str += '<td class="td8"><input type="number" class="layui-input content" readonly value="'+data[key].content+'"></td>';
                    str += '<td class="td9"><input type="number" class="layui-input loss_rate" value="'+data[key].loss_rate+'"></td>';
                    str += '<td class="td10"><input type="number" class="layui-input no_price" value="'+data[key].no_price+'">';
                    str += '<td class="td11"><input type="number" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td class="td12"><input type="text" class="layui-input explain" value="'+data[key].explain+'"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                parent.render_from();
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }
        });


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }
            if(parent_page == 'basal'){
                var str = '';
                var nums = $("#list_list tr", parent.document).length;

                var typeArr = parent.typeArr;
                var basetypeArr = parent.basetypeArr;

                var str = '';
                for (var key in data){

                    if(parent_type == 3 || parent_type == 4){
                        data[key].content_exp = 1;
                        data[key].content = 1;
                        data[key].loss_rate = 0;
                    }

                    nums++;
                    str += '<tr>';
                    str += '<td class="td1" style="width: 45px">'+nums+'</td>';
                    str += '<td class="td2"><select class="layui-select type" lay-filter="type">';
                    str += '<option value="">请选择</option>';
                    for(var j in typeArr){
                        if(data[key].type == j){
                            str += '<option value="'+j+'" selected>'+typeArr[j]+'</option>';
                        }else{
                            str += '<option value="'+j+'">'+typeArr[j]+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td class="td3"><select class="layui-select basetype">';
                    str += '<option value="">请选择</option>';

                    var this_basetype = basetypeArr[data[key].type];
                    for(var j=0;j<this_basetype.length;j++){
                        if(data[key].basetype == this_basetype[j].name){
                            str += '<option value="'+this_basetype[j].name+'" selected>'+this_basetype[j].name+'</option>';
                        }else{
                            str += '<option value="'+this_basetype[j].name+'">'+this_basetype[j].name+'</option>';
                        }
                    }
                    str += '</select></td>';
                    str += '<td class="td4"><input type="text" class="layui-input name" value="'+data[key].name+'"></td>';
                    str += '<td class="td5"><textarea class="layui-textarea curarea guige">'+data[key].guige+'</textarea></td>';
                    str += '<td class="td6"><input type="text" class="layui-input valunit" value="'+data[key].valunit+'"></td>';
                    str += '<td class="td7"><input type="text" class="layui-input content_exp" value="'+data[key].content_exp+'"></td>';
                    str += '<td class="td8"><input type="number" class="layui-input content" readonly value="'+data[key].content+'"></td>';
                    str += '<td class="td9"><input type="number" class="layui-input loss_rate" value="'+data[key].loss_rate+'"></td>';
                    str += '<td class="td10"><input type="number" class="layui-input no_price" value="'+data[key].no_price+'">';
                    str += '<td class="td11"><input type="number" class="layui-input price" value="'+data[key].price+'"></td>';
                    str += '<td class="td12"><input type="text" class="layui-input explain" value="'+data[key].explain+'"></td>';
                    str += '</tr>';
                }
                $("#list_list", parent.document).append(str);
                parent.render_from();
                if (typeof(window.parent.update_refresh_row_func)!="undefined"){
                    window.parent.update_refresh_row_func();
                }
            }
            layer_close();
        });




    });





</script>
</body>
</html>
